package main;

/**
*
* @author Mantas, Ramūnas, Vilius
*/
public class ChanelDevice {
    static String[][] SA;
    static String[][] DA;
    static int SO;
                    /*
                    *  SO= 1 – vartotojo atmintis,
                    *  SO= 2 – supervizorinė atmintis, TODO
                    *  SO= 3 – išorinė atmintis,
                    *  SO= 4 – įvedimo srautas;
                    */
    static int DO;
                    /*
                    *  DO= 1 – vartotojo atmintis,
                    *  DO= 2 – supervizorinė atmintis, TODO
                    *  DO= 3 – išorinė atmintis,
                    *  DO= 4 – išvedimo srautas;
                    */
    static int takenChanelIn;
    static int takenChanelOut;
    public ChanelDevice(){
            SA = null;
            DA = null;
            SO = 0;
            DO = 0;
    }

    public void XCHG(){
            String[][] memory1 = takeInputChanel(SO);
            String[][] memory2 = takeOutputChanel(DO);

            if(memory1 != null && memory2 != null){
                    memory1 = memory2;
                    freeInputChanel();
                    freeOutputChanel();
            }
    }

    public String[][] takeInputChanel(int memory){
            switch(memory){
                    case 1: if(takenChanelIn == 0){
                            takenChanelIn = 1;
                            return Memory.userMemory;
                    }
                    break;
                    case 2: if(takenChanelIn == 0){
                            takenChanelIn = 2;
                            //return ;
                    }
                    break;
                    case 3: if(takenChanelIn == 0){
                            takenChanelIn = 3;
                            //return ;
                    }
                    break;
                    case 4: if(takenChanelIn == 0){
                            takenChanelIn = 4;
                            //return ;
                    }
                    break;
            }
            return null;
    }
    
    public String[][] takeOutputChanel(int memory){
            switch(memory){
                    case 1: if(takenChanelOut == 0){
                            takenChanelOut = 1;
                            return Memory.userMemory;
                    }
                    break;
                    case 2: if(takenChanelOut == 0){
                            takenChanelOut = 2;
                            //return ;
                    }
                    break;
                    case 3: if(takenChanelOut == 0){
                            takenChanelOut = 3;
                            //return ;
                    }
                    break;
                    case 4: if(takenChanelOut == 0){
                            takenChanelOut = 4;
                            //return ;
                    }
                    break;
            }
            return null;
    }

    public void freeInputChanel(){
            takenChanelIn = 0;
    }    
    
    public void freeOutputChanel(){
            takenChanelOut = 0;
    }
}
